﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.Model;
using AvatarHelper;

public partial class Management_ResumeHits : System.Web.UI.Page
{
    int _page;
    int _take = 20;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (var _adc = DBHelper.GetDataContext())
            {
                this.Bind(_page);
            }
        }
    }
    protected void Bind(int _page)
    {
        using (var _adc = DBHelper.GetDataContext())
        {
            lbl_Current.Text = (_page + 1).ToString();
            lbl_Total.Text = (_adc.Resume.Count(r => r.PersonalBasicInfo != null && r.JobIntention != null) / _take).ToString();
            GridView1.DataSource = _adc.Resume.Where(r => r.PersonalBasicInfo != null && r.JobIntention != null).OrderByDescending(r => r.ViewCount).Skip(_take * _page).Take(_take);
            GridView1.DataBind();
        }
    }
    protected void btn_Up_Click(object sender, EventArgs e)
    {
         _page = Convert.ToInt32(lbl_Current.Text) - 1;
        if (_page < Convert.ToInt32(lbl_Total.Text) - 1) _page += 1;
        this.Bind(_page);
    }
    protected void btn_Down_Click(object sender, EventArgs e)
    {
        _page = Convert.ToInt32(lbl_Current.Text) - 1;
        if (_page > 0) _page -= 1;
        this.Bind(_page);
    }
    protected void btn_Goto_Click(object sender, EventArgs e)
    {
        _page = 0;
        try
        {
            if (!string.IsNullOrEmpty(txt_Page.Text))
            {
                _page = Convert.ToInt32(txt_Page.Text) - 1;
            }
        }
        catch { }
        this.Bind(_page);
    }
}
